﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Tools
{
    public class SmsHelper
    {
        private static string strReg = "101100-WEB-HUAX-541537";    //注册号（由华兴软通提供）
        private static string strPwd = "RBOVBUUH";                  //密码（由华兴软通提供）
        private static string strSourceAdd = "";                                   //子通道号，可为空（预留参数）
        private static string strUrl = "http://www.stongnet.com/sdkhttp/sendsms.aspx";


        public static bool SendMessage(string phoneNumber, string context)
        {
            //要发送的内容
            string strSend = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd +
                             "&phone=" + phoneNumber + "&content=" + context;
            string strRes = HttpHelper.Post(strUrl, strSend);
            return strRes.StartsWith("result=0");
        }

        public static bool SendMessage(IEnumerable<string> phoneNumbers, string context)
        {
            if (phoneNumbers == null) return false;
            string strPhones = "";
            foreach (string _phoneNum in phoneNumbers)
            {
                if (string.IsNullOrEmpty(strPhones) == false) strPhones += ",";
                strPhones += _phoneNum;
            }
            //要发送的内容
            string strSend = "reg=" + strReg + "&pwd=" + strPwd + "&sourceadd=" + strSourceAdd +
                             "&phone=" + strPhones + "&content=" + context;
            string strRes = HttpHelper.Post(strUrl, strSend);
            return strRes.StartsWith("result=0");
        }
    }
}
